﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;
using BOHVote.Entity;
 

namespace BOH.Information
{
    public partial class GovrenApplyList : System.Web.UI.Page
    {
        BHUser user = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindPeriod();
                if (Session["User"] != null)
                {
                    user = (BHUser)Session["User"];
                    if (user.RightType == "G")
                    {
                        UnitGovernBind(user.GovernID);
                    }
                    else if (user.RightType == "C" || user.RightType == "A")
                    {
                        UnitGovernBind("");
                    }

                }
            }
        }

        public void BindPeriod()
        {
            DataSet dst = PeriodClass.getAperiod();
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                ListItem li = new ListItem(dr["ApplyPeriodName"].ToString(), dr["ApplyPeriodID"].ToString());
                drpApplyPeriod.Items.Add(li);
            }
        }

        public void UnitGovernBind(string GovernID)
        {
            DataSet dstGovern = null;

            dstGovern = UnitClass.getGovernByGovernID(GovernID);

            if (dstGovern.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in dstGovern.Tables[0].Rows)
                {
                    if (row["GovernID"].ToString().Trim().Length != 0)
                    {
                        string strGovernID = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(row["GovernID"].ToString())).Replace("+", "%2B");
                        ListItem li = new ListItem(row["GovernName"].ToString(), strGovernID);
                        this.drpGovren.Items.Add(li);
                    }
                }
            }
        }

    }
}
